package com.yinquan.util;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yishun.springboot.pojo.YzwProjectAttendanceListNew;

/**
 * 
 * @date   2021年5月17日 下午9:00:37
 * @author XiaoHuang
 *
 */
public class ParseYzwResult {

	/**
	 * 成功条件下返回记录条数，否则返回空
	 * @param resultStr
	 * @return
	 */
	public  Integer parseYzwCodeAndGetRecordsTotal(String resultStr) {
		JSONObject jsonObject = JSONObject.parseObject(resultStr);
		if(jsonObject.get("code").equals("0") && jsonObject.get("message").equals("调用成功"))
		return jsonObject.getInteger("recordsTotal");
		else
		return null;
	}
	
	/**
	 * 返回结果code没有为0返回空
	 * @param resultStr
	 * @return
	 */
	public  String parseYzwCode(String resultStr) {
		JSONObject jsonObject = JSONObject.parseObject(resultStr);
		if(!jsonObject.get("code").equals("0"))
		return null;
		else
		return jsonObject.getString("data");
	}
	
	/**
	 * 请求失败的情况下和记录条数为0返回空返回空和0，成的情况下返回数据
	 * @param dataStr
	 * @return
	 */
	public String parseYzwOutData(String dataStr) {
		JSONObject jsonObject = JSONObject.parseObject(dataStr);
		
		dataStr = parseYzwCode(dataStr);
		if(dataStr == null)
			return null;
		else
			jsonObject = JSONObject.parseObject(dataStr);
		
		//请求成功但是，记录为0条的情况
		if(jsonObject.getInteger("recordsTotal") == 0)
		return "0";
		//成功的情况
		else
		return jsonObject.getString("data");
	}
	
	/**
	 * 解析{data:{"data":""}}
	 * @param dataStr
	 * @return
	 */
	public String parseYzwInData(String dataStr) {
		JSONObject jsonObject = JSONObject.parseObject(dataStr);
		
		
		//请求成功但是，记录为0条的情况
		if(jsonObject.getInteger("recordsTotal") == 0)
		return "0";
		//成功的情况
		else
		return jsonObject.getString("data");
	}
	
	/**
	 * 解析成考勤数据格式【考勤数组】
	 * @param dataStr
	 * @return
	 */
	public  List<YzwProjectAttendanceListNew> parseArrayToAtt(String arrayStr) {
		return  JSONObject.parseArray(arrayStr,YzwProjectAttendanceListNew.class);
	}
	
//	public static void main(String[] args) {
//		String resultStr = "{\"data\":{\"recordsTotal\":109970,\"data\":[{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":2956861,\"WorkerName\":\"余志远\",\"IDCardNumber\":\"440781198110241935\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:12:00+08:00\",\"FinalExitTime\":\"2021-05-17T15:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:12:00+08:00\",\"CardNumber\":\"241935\",\"Time\":\"2021-05-16T23:59:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/2109ec7d44104958acd49fc3e3799035-2956861.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":2956861,\"WorkerName\":\"余志远\",\"IDCardNumber\":\"440781198110241935\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:12:00+08:00\",\"FinalExitTime\":\"2021-05-17T15:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:12:00+08:00\",\"CardNumber\":\"241935\",\"Time\":\"2021-05-16T23:57:00+08:00\",\"Type\":2,\"CheckChannel\":\"f75d3a841dbb7241\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/44ed2afb156f4c46b4fafecf9feee6ef-2956861.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"f75d3a841dbb7241\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":2956861,\"WorkerName\":\"余志远\",\"IDCardNumber\":\"440781198110241935\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:12:00+08:00\",\"FinalExitTime\":\"2021-05-17T15:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:12:00+08:00\",\"CardNumber\":\"241935\",\"Time\":\"2021-05-16T23:56:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/8972353784854f46a0a1faa702eff77c-2956861.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":3555235,\"WorkerName\":\"王军\",\"IDCardNumber\":\"510521198109045874\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:57:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:57:00+08:00\",\"CardNumber\":\"45874\",\"Time\":\"2021-05-16T23:54:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/ffb8f3f3a97b4eafb42e3acd5a5034c7-3555235.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.8},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":3555235,\"WorkerName\":\"王军\",\"IDCardNumber\":\"510521198109045874\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:57:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:57:00+08:00\",\"CardNumber\":\"45874\",\"Time\":\"2021-05-16T23:53:00+08:00\",\"Type\":2,\"CheckChannel\":\"75db4863a21b086e\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/84d9261d799b4635971f38bb454d349c-3555235.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"75db4863a21b086e\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":325437,\"SubContractorSysNo\":25353,\"SubContractorName\":\"深圳市丰畅建筑劳务有限责任公司\",\"Gender\":0,\"TeamSysNo\":440136,\"TeamName\":\"丰畅普工班\",\"WorkerSysNo\":815144,\"WorkerName\":\"潘建平\",\"IDCardNumber\":\"362302197306041513\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T19:24:00+08:00\",\"FinalExitTime\":\"2021-05-17T19:21:00+08:00\",\"FinalAttendance\":\"2021-05-17T19:24:00+08:00\",\"Time\":\"2021-05-16T23:53:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/a718ff4f108041eb81fa8dedeb7d6b42-815144.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":3555235,\"WorkerName\":\"王军\",\"IDCardNumber\":\"510521198109045874\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:57:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:57:00+08:00\",\"CardNumber\":\"45874\",\"Time\":\"2021-05-16T23:52:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/a420183534ce4531989cd820facd7d8f-3555235.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":3555235,\"WorkerName\":\"王军\",\"IDCardNumber\":\"510521198109045874\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:57:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:57:00+08:00\",\"CardNumber\":\"45874\",\"Time\":\"2021-05-16T23:51:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/28108f1906094b94b8d523ef7852e30b-3555235.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":338832,\"SubContractorSysNo\":19366,\"SubContractorName\":\"深圳市中航装饰设计工程有限公司\",\"Gender\":0,\"TeamSysNo\":527411,\"TeamName\":\"油漆班组\",\"WorkerSysNo\":3555235,\"WorkerName\":\"王军\",\"IDCardNumber\":\"510521198109045874\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:57:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:55:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:57:00+08:00\",\"CardNumber\":\"45874\",\"Time\":\"2021-05-16T23:49:00+08:00\",\"Type\":2,\"CheckChannel\":\"f75d3a841dbb7241\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/f49fd1e26afc48d9b4d819c567326129-3555235.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"f75d3a841dbb7241\",\"FaceSimilarity\":0.9},{\"ProjectSysNo\":331222,\"SubContractorSysNo\":2407,\"SubContractorName\":\"潍坊宏源防水工程有限公司\",\"Gender\":0,\"TeamSysNo\":464737,\"TeamName\":\"宏源管理人员\",\"WorkerSysNo\":11146589,\"WorkerName\":\"王进\",\"IDCardNumber\":\"522422199804154078\",\"WorkerStatus\":\"在场\",\"FinalEntryTime\":\"2021-05-17T20:20:00+08:00\",\"FinalExitTime\":\"2021-05-17T20:18:00+08:00\",\"FinalAttendance\":\"2021-05-17T20:20:00+08:00\",\"CardNumber\":\"154078\",\"Time\":\"2021-05-16T23:49:00+08:00\",\"Type\":1,\"CheckChannel\":\"abf3a02a805745b2\",\"Image\":\"https://lwres.yzw.cn/labor/attendance/Original/2021/0516/b86d4520567847e3bdb4aec9ed69c082-11146589.jpg\",\"Temperature\":35.0,\"SerialNumber\":\"abf3a02a805745b2\",\"FaceSimilarity\":0.8}],\"PassDataPermissionAuth\":false,\"PassFilterDeletedStatus\":false,\"OnlyTopAndSelf\":false,\"EnableSolrQuery\":false,\"PageIndex\":0,\"PageSize\":10,\"draw\":0},\"code\":\"0\",\"message\":\"调用成功\"}";
//		List<YzwProjectAttendanceListNew> yzwAttendanceList = parseArrayToAtt(parseYzwInData(parseYzwCode(resultStr)));
//		log.info("yzwAttendanceList:"+yzwAttendanceList.toString());
//	}
}
